<?php
/**
 * 小程序提醒
 */
namespace app\mini\controller;
class Notify extends Pre
{
    //获取open_id
    public function index(){
        $data = input('param.');
        $userInfo = $this -> loginInfo;
        if ($userInfo['open_id'] === null && $data['js_code']){
            $WxMini = new \app\common\logic\WxMini();
            $WxUserInfo =  $WxMini -> getOpenId();
            $WxUserInfo = json_decode($WxUserInfo,true);
            if ($WxUserInfo['openid'])
                \app\common\model\Account::where('id', $userInfo['id'])
                    ->update(['open_id' => $WxUserInfo['openid']]);
            $userInfo['open_id'] =$WxUserInfo['openid'];
        }
        return $userInfo;
    }

    //获取form_id
    public function getFormID(){
        $form_id = input('form_id');
        $loginInfo = $this -> loginInfo;
        if ($loginInfo['open_id'] && $form_id){
            $WxMini = new \app\common\logic\WxMini();
            $WxMini -> addFromID($loginInfo['open_id'],$form_id);
            return true;
        }

    }

}